<?php
    require "config.php";
    $dbh = dbConnect();
    $id = $_GET["id"];
    try{
        if($_POST){
            $sql = "update users set user_pwd = '{$_POST["user-pwd"]}' where user_id = {$_POST["user-id"]}";
            $sth = $dbh->query($sql);
            if($sth){
                echo "<script>alert('修改成功')</script>"; 
                echo "<script>window.location.href='after-users.php'</script>"; 
            }else{
                echo "<script>alert('修改失败')</script>"; 
            }
        }else{
            $sql = "select * from users  where user_id = {$id}";
            $sth = $dbh->query($sql);
            $result = $sth->fetch();
        }
       
    }catch(PDOException $e){
        print('Error:'.$e->getMessage());
        die();
    }
?>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>后台管理主页面</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="./css/after-updateUsers.css">
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
</head>

<body>
    <header>
        <div class="page-header">
            <h1>论坛用户管理</h1>
        </div>
    </header>

    <article>
        <nav>
            <ul class="nav nav-tabs">
                <li role="presentation"><a href="after-message.php">留言管理</a></li>
                <li role="presentation" class="active"><a href="after-users.php">用户管理</a></li>
                <li role="presentation"><a href="after-manager.php">管理员管理</a></li>
            </ul>
        </nav>

        <div>
            <form action="after-updateUsers.php" method="POST">
                <input type="text" name="user-id" value="<?= $result["user_id"]?>" hidden>
                <input type="text" value="<?= $result["user_name"]?>" readonly>
                <input type="text" name="user-pwd" placeholder="请输入更改后的密码">
                <input type="submit" value="确认修改">
            </form>
        </div>
    </article>

</body>

</html>